**************************************************************************************************
*** This do file creates the replication results for 
*** "Environmental regulation and the cross-border diffusion of new technology:
*** Evidence from automobile patents"							 	
*** Antoine Dezechlepretre (LSE)
*** Eric Neumayer (LSE)			
*** Richard Perkins (LSE)
*** 							
*** Published in: Research Policy, 44 (1), 2015, pp. 244-257
**************************************************************************************************
**************************************************************************************************
/* Note: 
You have to change "local DIR" to the directory you copy the original stata files contained 	
and then run the do file. 													*/
**************************************************************************************************

drop _all
clear matrix
clear mata



***********************************************************************************
local DIR = "D:\Research\Patents\Patstat\"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************



* Note: throughout the dofile we use the first forward lag of the dependent variable (F1) and the contempraneous values for all right hand side variables - this is equivalent to using the contempraneous value of the dependent variable and lagging all RHS variables which is how our empirical model is specified



******************************************************************
* Table 1 Summary statistics and bivariate correlation matrix
******************************************************************


**** Summary statistics

* Note: summary statistics are provided on the main estimation sample

use "Article for Research Policy (patents)_main", clear
tab year, gen(year_)

* Define estimation sample
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_*, fe
* Summary statistics
sum patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports if e(sample)

**** Corelation matrix
corr patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports if e(sample)


* Variance Inflation Statistics

collin regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports



******************************************************************
* Table 2 Main estimation results
******************************************************************

use "Article for Research Policy (patents)_main", clear
tab year, gen(year_)

xtnbreg patents_granted_F1 regul_recipient regul_source ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq1
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq2
esttab eq1 eq2 using table2.csv , margin nodepvars b(%10.4f) csv se(%10.4f) nolines noeqlines nogaps drop(*year*) replace star(* 0.1 ** 0.05 *** 0.01) scalars(N N_g ) sfmt(a1) type


**********************************************************************************************************************
* Table 3 Estimation results for developed-developing (and developed-developed) country flows
**********************************************************************************************************************

use "Article for Research Policy (patents)_main", clear
tab year, gen(year_)

estimates clear

* OECD to non-OECD
xtnbreg patents_granted_F1 regul_recipient regul_source ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_* if oecd_nonoecd, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq1
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_* if oecd_nonoecd, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq2

* Major car producers from OECD to non-OECD
xtnbreg patents_granted_F1 regul_recipient regul_source ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_* if major_oecd_nonoecd, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq3
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_* if major_oecd_nonoecd, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq4

* OECD to OECD
xtnbreg patents_granted_F1 regul_recipient regul_source ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_* if oecd_oecd, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq5
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_* if oecd_oecd, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq6

esttab eq1 eq2 eq3 eq4 eq5 eq6 using table3.csv , margin nodepvars b(%10.4f) csv se(%10.4f) nolines noeqlines nogaps drop(*year*) replace star(* 0.1 ** 0.05 *** 0.01) scalars(N N_g ) sfmt(a1) type



*************************************************************
* Table 4 Robustness tests (I)
*************************************************************

use "Article for Research Policy (patents)_main", clear
tab year, gen(year_)

estimates clear

* Add squared distance
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance regul_distance_square ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq1

* Add inventions in destination country as additional control
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ln_recipient_inventions_granted ipr ln_car_imports year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq2

* Add total flow of patents from country i to country j in year t in all technologies other than automotive emissions abatement technology as additional control
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech patents_granted_alltechs ipr ln_car_imports year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq3

* Use predicted values of regulation from 1st stage regression (for endogeneity)
* Note: predicted regulation is from a first stage OLS regression where regulation is instrumented by regulation in neighbouring countries
xtnbreg patents_granted_F1 regul_recipient_pred regul_source_pred regul_distance_pred ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq4

* Use patent applications instead of grants
xtnbreg patents_applied_F1 regul_recipient regul_source regul_distance ln_source_inventions_applied ln_stock_applications_recipient ln_patents_applied_othertech ipr ln_car_imports year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq5

esttab eq1 eq2 eq3 eq4 eq5 using table4.csv , margin nodepvars b(%10.4f) csv se(%10.4f) nolines noeqlines nogaps drop(*year*) replace star(* 0.1 ** 0.05 *** 0.01) scalars(N N_g ) sfmt(a1) type


*************************************************************
* Table 5 Robustness tests (II)
*************************************************************

estimates clear

* EU as one entity
use "Article for Research Policy (patents)_EUasone", clear
tab year, gen(year_)
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq1

use "Article for Research Policy (patents)_main", clear
tab year, gen(year_)

* no JP US DE
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_* if source!="USA" & source!="JPN" & source!="DEU" & destination!="USA" & destination!="JPN" & destination!="DEU", fe vce(bootstrap, reps(50) seed(10101))
estimates store eq2

* include dummy variables for EPO members
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports recipient_epo_member source_epo_member source_recipient_epo_member year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq3

* Major OECD car producers to major OECD car producers
xtnbreg patents_granted_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted ln_stock_grants_recipient ln_patents_granted_othertech ipr ln_car_imports year_* if major_oecd_major_oecd, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq4

* restricting the sample to fuel injection technologies
xtnbreg patents_granted_fi_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted_fi ln_stock_grants_recipient_fi ln_patents_granted_othertech_fi ipr ln_car_imports year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq5

* restricting the sample to OBD technologies
xtnbreg patents_granted_obd_F1 regul_recipient regul_source regul_distance ln_source_inventions_granted_obd ln_stock_grants_recipient_obd ln_patents_granted_othertech_obd ipr ln_car_imports year_*, fe vce(bootstrap, reps(50) seed(10101))
estimates store eq6

esttab eq1 eq2 eq3 eq4 eq5 eq6 using table5.csv , margin nodepvars b(%10.4f) csv se(%10.4f) nolines noeqlines nogaps drop(*year*) replace star(* 0.1 ** 0.05 *** 0.01) scalars(N N_g ) sfmt(a1) type


